﻿using AutoMapper;
using B.S.Procurement.Domain;
using B.S.Procurement.Error;
using B.S.Procurement.Read.Api.Application.Command.VendorModelCommand;
using MediatR;
using SqlSugar;

namespace B.S.Procurement.Read.Api.Application.CommandHander.VendorModelCommandHander
{
    public class ShowVendorModelCommandHander : IRequestHandler<ShowVendorModelCommand, ApiResult<List<VendorModel>>>
    {
        private readonly IMapper mapper;
        private readonly ISqlSugarClient db;

        public ShowVendorModelCommandHander(IMapper mapper, ISqlSugarClient db)
        {
            this.mapper = mapper;
            this.db = db;
        }

        public async Task<ApiResult<List<VendorModel>>> Handle(ShowVendorModelCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<VendorModel>> result = new ApiResult<List<VendorModel>>();

            var list = await db.Queryable<VendorModel>()
                                .Where(x => x.Del == false && x.VendorId == request.VendorId)
                                .ToListAsync();

            result.Data = list;

            result.Code = ApiEnum.success;
            result.Msg = "查询成功";

            return await Task.FromResult(result);
        }
    }
}
